package com.wc.AlgoOJ_train.train2_DP训练.c6.DP0302;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/13 23:06
 * @description 没有上司的舞会
 * http://43.138.190.70:8888/p/DP0302
 */
public class Main2 {
    static int maxN = (int) 1e5 + 7;
    // 头节点连接的第一个节点
    static int[] head = new int[maxN];
    // 下一条边
    static int[] ne = new int[maxN << 1];
    // 下一条边的节点
    static int[] e = new int[maxN << 1];

    static int idx = 0;

    static int n;
    static long[][] dp = new long[maxN][2];
    static int[] happy = new int[maxN];
    static int u, v;
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for (int i = 2; i <= n; i++) {
            u = sc.nextInt();
            v = i;
            add(u, v);
        }
        for (int i = 1; i <= n; i++) {
            happy[i] = sc.nextInt();
        }
        dfs(1);
        System.out.println(Math.max(dp[1][0], dp[1][1]));
    }

    static void dfs(int u) {
        dp[u][1] = happy[u];

        for (int i = head[u]; i != 0; i = ne[i]) {
            int v = e[i];
            dfs(v);
            dp[u][0] += Math.max(dp[v][0], dp[v][1]);
            dp[u][1] += dp[v][0];
        }
    }

    // u - > v;
    static void add(int u, int v) {
        e[++idx] = v;
        // 前插法
        ne[idx] = head[u];
        head[u] = idx;
    }

    static class FastReader {
        StringTokenizer st;
        BufferedReader br;

        FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}
